﻿using System;
using Glue;
using Glue.Internals;
using Xunit;

namespace GlueTests
{
    public class PrimitivesTest
    {
        public enum AnEnum { First, Second, Third }

        [Fact]
        public void Should_create_primitives()
        {
            AssertCreatesInstance(typeof(int));
        }

        [Fact]
        public void Should_create_Strings()
        {
            AssertCreatesInstance(typeof(String));
        }

        [Fact]
        public void Should_create_Enums()
        {
            AssertCreatesInstance(typeof(AnEnum));
        }

        [Fact]
        public void Should_create_DateTimes()
        {
            AssertCreatesInstance(typeof(DateTime));
        }

        [Fact]
        public void Should_create_TimeSpans()
        {
            AssertCreatesInstance(typeof(TimeSpan));
        }

        [Fact]
        public void Should_throw_exception_when_type_is_not_primitive()
        {
            Assert.Throws(typeof (GlueException), () => Primitives.CreateInstance(GetType()));
        }

        

        private void AssertCreatesInstance(Type type)
        {
            Assert.Equal(Primitives.CreateInstance(type).GetType(), type);
        }


    }
}
